function request(obj){
    return new Promise((resolve, reject) => {
        // 处理obj.method的默认值
        obj.method = obj.method || "get";
        if(obj.url == undefined){ // 如果没有请求地址，就不发送请求了
            alert("请传入请求地址");
            return;
        }
        // 处理同步异步的默认值
        if(obj.async === undefined){
            obj.async = true;
        }
        // 处理data
        if(obj.data != undefined){
            var str = '';
            var f = '';
            for(var attr in obj.data){
                str += f+attr+"="+obj.data[attr];
                f = '&';
            }
        }
        var ajax = new XMLHttpRequest();
        ajax.open(obj.method,obj.url,obj.async);
        ajax.onreadystatechange=function(){
            if(ajax.readyState==4 && ajax.status==200){
                var res = ajax.responseText;
                res = JSON.parse(res);
                // 处理另外的事情
                resolve(res);
            }
        }
        if(obj.headers) {
            for(var key in obj.headers) {
                ajax.setRequestHeader(key, obj.headers[key])
            }
        }
        if(obj.method == "post"){
            ajax.setRequestHeader("content-type","application/x-www-form-urlencoded");
        }

        if(obj.data == undefined){
            ajax.send();
        }else{
            ajax.send(str);
        }
    })
}